package com.aliyun.messagemgt.repository;

import com.aliyun.messagemgt.converter.BaseReceiveGroupRangeConverter;
import com.aliyun.messagemgt.domain.repository.IBaseReceiveGroupRangeRepository;
import com.aliyun.messagemgt.dto.base.BaseReceiveGroupRangeAddCmd;
import com.aliyun.messagemgt.dto.base.BaseReceiveGroupRangeDTO;
import com.aliyun.messagemgt.entities.BaseReceiveGroupRange;
import com.aliyun.messagemgt.repository.mappers.BaseReceiveGroupRangeMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 基础表-接收组范围表 服务实现类
 * </p>
 *
 * @author wugongzi
 * @since 2021-09-28
 */
@Service
public class BaseReceiveGroupRangeMybatisRepository implements IBaseReceiveGroupRangeRepository {

    @Autowired
    private BaseReceiveGroupRangeMapper baseReceiveGroupRangeMapper;

    @Override
    public List<BaseReceiveGroupRangeDTO> selectByGroupIdList(List<Long> groupIdList) {
        QueryWrapper<BaseReceiveGroupRange> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("group_id", groupIdList);
        queryWrapper.eq("is_deleted","N");
        List<BaseReceiveGroupRange> baseReceiveGroupRangeList = baseReceiveGroupRangeMapper.selectList(queryWrapper);
        return BaseReceiveGroupRangeConverter.INSTANCE.baseReceiveGroupRangeList2baseReceiveGroupRangeDTOList(baseReceiveGroupRangeList);
    }

    @Override
    public int deleteByGroupId(Long groupId) {
        QueryWrapper<BaseReceiveGroupRange> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("group_id", groupId);
        int rangeDeleteCount = baseReceiveGroupRangeMapper.delete(queryWrapper);
        return rangeDeleteCount;
    }

    @Override
    public void add(List<BaseReceiveGroupRangeAddCmd> baseReceiveGroupRangeAddCmdList) {
        List<BaseReceiveGroupRange> baseReceiveGroupRangeList = BaseReceiveGroupRangeConverter.INSTANCE.baseReceiveGroupRangeAddCmdList2baseReceiveGroupRangeList(baseReceiveGroupRangeAddCmdList);
        baseReceiveGroupRangeMapper.batchInsert(baseReceiveGroupRangeList);
    }

    @Override
    public List<BaseReceiveGroupRangeDTO> selectByGroupId(Long groupId) {
        QueryWrapper<BaseReceiveGroupRange> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("group_id", groupId);
        queryWrapper.eq("is_deleted","N");
        List<BaseReceiveGroupRange> baseReceiveGroupRangeList = baseReceiveGroupRangeMapper.selectList(queryWrapper);
        return BaseReceiveGroupRangeConverter.INSTANCE.baseReceiveGroupRangeList2baseReceiveGroupRangeDTOList(baseReceiveGroupRangeList);
    }
}
